 *********************************************************************************
*** Figure 5
*********************************************************************************

* Project: 	European public opinion twd collective defence
* Authors: 	Matthias Mader
* Date:		Sep 2023	

* Data: VW Project, Post-Ukraine Survey, Pan-European survey (W1)

*********************************************************************************

*** Setup

	clear
	set more off            						// Disable partitioned output
	set dp period									// Use comma instead of dot for decimals
	set linesize 80         						// Line size limit to make output more readable
	macro drop _all         						// clear all macros
	set scheme plotplainblind, permanent				// set graph scheme, e.g., cleanplots, plottig, plotplainblind, burd3, s1mono
	graph set window fontface "Arial"				// set font in graphs | "Arial" | "Times New Roman"


*** Open data set
use "DATA_clean.dta", clear


*** Correlation between DVs
	pwcorr ally1_pre_r ally1_post_r policy_LVAsoli_pre_r policy_LVAsoli_post_r policy_essential_pre_r policy_essential_post_r
	pwcorr ally1_r policy_LVAsoli_r policy_essential_r 

*** Military alliances should be essential

	reg ally1_pre_r c.thr_RUS_pre_r##i.W1_QCOUNTRY age i.female i.educat leri_r
	margins, dydx(thr_RUS_pre_r) at(W1_QCOUNTRY=(7 8 9 10 11 13 15 19 24 25)) post
	estimates store m1

	reg ally1_post_r c.thr_RUS_post_r##i.W1_QCOUNTRY age i.female i.educat leri_r
	margins, dydx(thr_RUS_post_r) at(W1_QCOUNTRY=(7 8 9 10 11 13 15 19 24 25)) post
	estimates store m2

	coefplot	(m1, mcolor(eltblue%50)	ciopts(lcolor(eltblue%50)	msymbol(circle) lwidth(.5)) msize(large) msymbol(circle) offset(.1))	/// 
				(m2, mcolor(red) 		ciopts(lcolor(red)			msymbol(circle) lwidth(.5)) msize(large) msymbol(circle) offset(-.1))	///
				, name(G5_1, replace) ///
		scheme(plotplainblind) ///
		title ("DV: Alliances essential part" " of [COUNTRY]'s security strategy ", size(large) box) ///
		coeflabels(1._at="Estonia" ///
				   2._at="Finland" ///
				   3._at="France" ///
				   4._at="Germany" ///
				   5._at="UK" ///
				   6._at="Hungary" ///
				   7._at="Italy" ///
				   8._at="Poland" ///
				   9._at="Spain" ///
				   10._at="Sweden" ///
				   , labsize (large)) ///
		grid(none) ///
		ylab(,grid) ///
		xscale(range(0 .6)) xlab(0 (.1) .6, labs(large))  ///
		xtitle("Effect of threat perception", size(large)) ///
		legend(ring(1) position(6) row(1) order(2 "10/2020" 4  "2/2023") size(large)) ///
		plotregion(margin(zero) lcolor(black)) ///
		graphregion(margin(-6 2 0 0)) ///
		xsize(2.5) ysize(3.5)


*** Willingness to use military force to defend ally (Latvia)

	reg  policy_LVAsoli_pre_r c.thr_RUS_pre_r##i.W1_QCOUNTRY age i.female i.educat leri_r
	margins, dydx(thr_RUS_pre_r) at(W1_QCOUNTRY=(7 8 9 10 11 13 15 19 24 25)) post
	estimates store m1

	reg  policy_LVAsoli_post_r c.thr_RUS_post_r##i.W1_QCOUNTRY age i.female i.educat leri_r
	margins, dydx(thr_RUS_post_r) at(W1_QCOUNTRY=(7 8 9 10 11 13 15 19 24 25)) post
	estimates store m2

	coefplot	(m1, mcolor(eltblue%50)	ciopts(lcolor(eltblue%50)	msymbol(circle) lwidth(.5)) msize(large) msymbol(circle) offset(.05))		///
				(m2, mcolor(red) 		ciopts(lcolor(red)			msymbol(circle) lwidth(.5)) msize(large) msymbol(circle) offset(-.05))	///
				, name(F5_2, replace) ///
		scheme(plotplainblind) ///
		title ("DV: Willingness to deploy troops" "to secure Latvian border", size(large) box) ///
		coeflabels(1._at="Estonia" ///
				   2._at="Finland" ///
				   3._at="France" ///
				   4._at="Germany" ///
				   5._at="UK" ///
				   6._at="Hungary" ///
				   7._at="Italy" ///
				   8._at="Poland" ///
				   9._at="Spain" ///
				   10._at="Sweden" ///
				   , labsize (large)) ///
		msize(large) ciopts(lwidth(thick)) ///
		grid(none) ///
		ylab(,grid) ///
		xscale(range(0 .6)) xlab(0 (.1) .6, labs(large)) ///
		xtitle("Effect of threat perception", size(large)) ///
		legend(ring(1) position(6) row(1) order(2 "10/2020" 4 "2/2023") size(large)) ///
		plotregion(margin(zero) lcolor(black)) ///
		graphregion(margin(-6 2 0 0)) ///
		xsize(2.5) ysize(3.5)



*** NATO is an essential part of COUNTRY's national security

	reg  policy_essential_pre_r c.thr_RUS_pre_r##i.W1_QCOUNTRY age i.female i.educat leri_r
	margins, dydx(thr_RUS_pre_r) at(W1_QCOUNTRY=(7 8 9 10 11 13 15 19 24 25)) post
	estimates store m1

	replace policy_essential_post_r  = ally1_post_r if W1_QCOUNTRY == 8 | W1_QCOUNTRY == 25 // "Fake data" --> Delete from Figure
	reg  policy_essential_post_r c.thr_RUS_post_r##i.W1_QCOUNTRY age i.female i.educat leri_r
	margins, dydx(thr_RUS_post_r) at(W1_QCOUNTRY=(7 8 9 10 11 13 15 19 24 25)) post
	estimates store m2

	coefplot	(m1, mcolor(eltblue%50)	ciopts(lcolor(eltblue%50)	msymbol(circle) lwidth(.5)) msize(large) msymbol(circle) offset(.05))		///
				(m2, mcolor(red) 		ciopts(lcolor(red)			msymbol(circle) lwidth(.5)) msize(large) msymbol(circle) offset(-.05))	///
				, name(F5_3, replace) ///
		scheme(plotplainblind) ///
		title ("NATO is an essential part" " of [COUNTRY]'s national security ", size(large) box) ///
		coeflabels(1._at="Estonia" ///
				   2._at="Finland" ///
				   3._at="France" ///
				   4._at="Germany" ///
				   5._at="UK" ///
				   6._at="Hungary" ///
				   7._at="Italy" ///
				   8._at="Poland" ///
				   9._at="Spain" ///
				   10._at="Sweden" ///
				   , labsize (large)) ///
		msize(large) ciopts(lwidth(thick)) ///
		grid(none) ///
		ylab(,grid) ///
		xscale(range(0 .6)) xlab(0 (.1) .6, labs(large)) ///
		xtitle("Effect of threat perception", size(large)) ///
		legend(ring(1) position(6) row(1) order(2 "10/2020" 4 "2/2023") size(large)) ///
		plotregion(margin(zero) lcolor(black)) ///
		graphregion(margin(-6 2 0 0)) ///
		xsize(2.5) ysize(3.5)
